package com.ktjy;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

/**
 * @author 黄军艳
 * @version 1.0
 * @date 2024/11/25  15:19
 */
public class EmployeeTest5 {
    public static void main(String[] args) {
        try {
            Class clz=Class.forName("com.ktjy.Employee");
            Constructor constructor=clz.getDeclaredConstructor();
            Object o=constructor.newInstance();
            Field empNo=clz.getDeclaredField("empNo");
            Field empName=clz.getDeclaredField("empName");
            Field empPost=clz.getDeclaredField("empPost");
            Field empSalary=clz.getDeclaredField("empSalary");
            empNo.setAccessible(true);
            empNo.set(o,"JD1006");
            empName.setAccessible(true);
            empName.set(o,"哇塞");
            empPost.setAccessible(true);
            empPost.set(o,"JAVA开发工程师");
            empSalary.setAccessible(true);
            empSalary.set(o,15000);
            Method method=clz.getDeclaredMethod("showInfo");
            method.invoke(o);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        }
    }
}
